Improve nearest-neighbor query perf#708
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #708 +/- ##
==========================================
- Coverage 93.67% 93.66% -0.02%
==========================================
Files 89 89
Lines 13621 13707 +86
==========================================
+ Hits 12759 12838 +79
- Misses 862 869 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
djhoese
left a comment
There was a problem hiding this comment.
Nice job. Thanks for finding this. I've always disliked the indexing done in the query so I'm glad to see it cleaned up. I had a couple questions, but otherwise the majority of this looks good to me.
Otherwise could you check pre-commit's failures? Thanks.
| if np.isnan(src_res): | ||
| radius_of_influence = dst_res | ||
| elif np.isnan(dst_res): | ||
| radius_of_influence = src_res | ||
| else: | ||
| radius_of_influence = max(src_res, dst_res) |
There was a problem hiding this comment.
Could you explain why this is better? Because it prefers the source resolution?
There was a problem hiding this comment.
It works just the same and avoids the all-nans warning print, which is quite expensive in Python. So it benefits only the worst-case scenario.
a17a10b to
2d09c3b
Compare
|
In your original description you talked about the performance of |
|
Oh and what was your test case for your timing? I'm surprised by how fast the query stuff was, but even more by how slow the NaN case was for the radius of influence stuff. |
|
One last thing: I'm not ignoring your other pyresample and satpy PRs, but I'm still catching up on real work after being out for a couple days and I'm trying to fully understand the changes before commenting. Thanks again for all these changes/fixes/improvements. |
pyresample/future/resamplers/nearest.py:496 replaces data.copy() with data.copy(deep=False) before swapping .data to a dask array. That avoids a deep copy of the underlying NumPy buffer.
I don't remember now, but I was measuring the specific code paths in isolation, not in a bigger system. I like efficient software.
Np, I was delaying too because I started working on the data I got processed 😄. |
Were you running things multiple times? I'm unable to get my laptop with a real world case to perform in a consistently better way. I'll try a few more things to sanity check... |
|
I don't remember what data you said you're processing, but I'm taking ABI L1b data (G16) and resampling it using nearest neighbor to the Satpy builtin "brazil" area. With current pyresample from datetime import datetime
from satpy import Scene
from glob import glob
scn = Scene(reader="abi_l1b", filenames=glob("/data/satellite/abi/20180623/OR_ABI-L1b-RadF-M3C*G16*.nc"))
scn.load(["C02"])
first = datetime.now()
new_scn = scn.resample("brazil", resampler="nearest")
new_scn["C02"].compute()
#new_scn.save_datasets(filename="C02_brazil.tif")
second = datetime.now()
print((second - first).total_seconds()) |
2d09c3b to
b23310e
Compare
|
In my PR body, I performed 3 distinct measurements on the individual methods directly, not the full pipeline. I do confirm that the improvements are still reproducible. I've also noticed I implemented one more valuable specialization to query_no_distance that brings 6% performance improvement in the neighbors=1 common case. |
|
Thanks. I've been off of work the last week or so but am catching up on things today. I'll try to review this when I get a chance. And yeah if you're testing the individual functions it makes sense to see these low-level improvements but then I not see them on the high-level when the majority of time is spent building the KDTree and the actual query time. |
mraspaud
left a comment
There was a problem hiding this comment.
LGTM, thanks for taking the time to simplify the processing!
query_no_distance:
runtime:
0.01383s -> 0.01279s(-7.5%).rss:
221096KB -> 204204KB(-7.6%)._verify_input_object_type numpy array:
runtime:
0.02705s -> 0.02002s(-26%).rss: same
_compute_radius_of_influence nan case:
runtime:
19.71s -> 2.10s.rss: same